home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Examples of using "volatile"?
- Date: 18 Jan 1996 16:03:16 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Jan18090316@qcd.lanl.gov>
- References: <4djoj2$mr1@post.gsfc.nasa.gov>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: Stephen Maher's message of 17 Jan 1996 21:09:54 GMT
-
- --text follows this line--
- In article <4djoj2$mr1@post.gsfc.nasa.gov> Stephen Maher
- <Stephen.Maher@gsfc.nasa.gov> writes:
- <snip>
- I'd like a concrete example(s) illustrating a reason to
- use the "volatile" type qualifier.
-
- The first place where I used it is when I was doing memory mapped
- i/o: when I read or wrote to a `memory' location, it was interpreted
- by a periphereal element as a request to do some communication; or
- report the result of one.
-
- I knew the `address' at which I had to read or write to. I knew how
- (using implementation defined features) I could create a pointer to
- this address. But, without volatile, the compiler always aggressively
- optimized two successive `reads' into one, or two successive `writes'
- into one. This of course, messed up the communication altogether :-)
-
- Adding a volatile fixed it; and gave me one more reason to learn C.
-
- I understand the *theory* behind volatile (e.g., to
- avoid unwanted side-effects?). I also realize it's
- probably implementation dependent. But some examples
- from any implementation should help me understand
- its use a little better.
-
- The above is probably the kind of example that you wanted. When I
- learnt C, I realized that there are situations involving
- setjmp/longjmp, where `volatile' is _required_ for a program to be
- portable. Naturally, such cases are _not_ implementation dependent.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-